home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Text / Edit / GoldED-Demo / installdata / golded / developer / scanner / examples / pascal / pascal.c
Encoding:
C/C++ Source or Header  |  1999-12-03  |  2.7 KB  |  100 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for Pascal-style functions & procedure.
  4.  
  5.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  6.   code and no library calls permitted. We have to put string constants into
  7.   the code segment (DICE compiler: option -ms1).
  8.   
  9.   DICE:
  10.   
  11.   dcc pascal.c -// -l0 -md -mRR -o golded:etc/scanner/pascal
  12.  
  13.   ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <exec/types.h>
  17.  
  18. #define UPPER(a) ((a) & 95)
  19.  
  20. ULONG
  21. ScanHandlerPascal(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  22. {
  23.     const char *version = "$VER: Pascal 1.2 (" __COMMODORE_DATE__ ")";
  24.  
  25.     if (len > 9) {
  26.  
  27.         if (UPPER(**text) == 'F') {
  28.  
  29.             if ((UPPER((*text)[1]) == 'U') && (UPPER((*text)[2]) == 'N') && (UPPER((*text)[3]) == 'C') && (UPPER((*text)[4]) == 'T') && (UPPER((*text)[5]) == 'I') && (UPPER((*text)[6]) == 'O') && (UPPER((*text)[7]) == 'N') && ((*text)[8] == ' ')) {
  30.  
  31.                 UBYTE *next;
  32.  
  33.                 // found FUNCTION
  34.  
  35.                 *text += 8;
  36.                 len   -= 8;
  37.  
  38.                 // ignore spaces before function name
  39.  
  40.                 while (len && ((**text == ' ') || (**text == 9))) {
  41.  
  42.                     ++*text;
  43.                     --len;
  44.                 }
  45.  
  46.                 // extract function name
  47.  
  48.                 for (next = *text; len--; ++next)
  49.  
  50.                     if ((UPPER(*next) < 'A') || (UPPER(*next) > 'Z'))
  51.  
  52.                         if ((*next < '0') || (*next > '9'))
  53.  
  54.                             if (*next != '_')
  55.  
  56.                                 break;
  57.  
  58.                 return(next - *text);
  59.             }
  60.         }
  61.         else if (UPPER(**text) == 'P') {
  62.  
  63.             if ((UPPER((*text)[1]) == 'R') && (UPPER((*text)[2]) == 'O') && (UPPER((*text)[3]) == 'C') && (UPPER((*text)[4]) == 'E') && (UPPER((*text)[5]) == 'D') && (UPPER((*text)[6]) == 'U') && (UPPER((*text)[7]) == 'R') && (UPPER((*text)[8]) == 'E') && ((*text)[9] == ' ')) {
  64.  
  65.                 UBYTE *next;
  66.  
  67.                 // found PROCEDURE
  68.  
  69.                 *text += 9;
  70.                 len   -= 9;
  71.  
  72.                 // ignore spaces before procedure name
  73.  
  74.                 while (len && ((**text == ' ') || (**text == 9))) {
  75.  
  76.                     ++*text;
  77.                     --len;
  78.                 }
  79.  
  80.                 // extract procedure name
  81.  
  82.                 for (next = *text; len--; ++next)
  83.  
  84.                     if ((UPPER(*next) < 'A') || (UPPER(*next) > 'Z'))
  85.  
  86.                         if ((*next < '0') || (*next > '9'))
  87.  
  88.                             if (*next != '_')
  89.  
  90.                                 break;
  91.  
  92.                 return(next - *text);
  93.             }
  94.         }
  95.     }
  96.  
  97.     return(FALSE);
  98. }
  99.  
  100.